/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * StatsPanel.java
 *
 * Created on Nov 9, 2010, 11:53:32 PM
 */

package doh.client;

import javax.swing.table.*;
import java.util.*;
import doh.service.*;
import doh.entity.*;

public class StatsPanel extends javax.swing.JPanel {
    private TableModel model_stats;
    
    /** Creates new form StatsPanel */
    public StatsPanel(UserSessionBeanRemote aBean) {
        UserSessionBeanRemote usb = aBean;
        String[] statsHeader = {"Player ID", "ELO Rating", "Games Played", "Win %", "Opponent %", "Rock %", "Paper %", "Scissors %"};
        List<Player> players = usb.getPlayers();
        int tableLength = players.size();
        Object [][] statsContent = new Object[tableLength][8];
        Iterator itr = players.iterator();
        int ii = 0;
        while (itr.hasNext()) {
            Player aPlayer = (Player)itr.next();
            statsContent[ii][0] = aPlayer.get_id();
            statsContent[ii][1] = aPlayer.get_rating();
            statsContent[ii][2] = aPlayer.get_games();
            statsContent[ii][3] = aPlayer.get_wper();
            statsContent[ii][4] = aPlayer.get_oper();
            statsContent[ii][5] = aPlayer.get_rocks();
            statsContent[ii][6] = aPlayer.get_papers();
            statsContent[ii][7] = aPlayer.get_scissors();
            ii++;
        }
        model_stats = new javax.swing.table.DefaultTableModel(statsContent, statsHeader);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        StatsTableScrollPane = new javax.swing.JScrollPane();
        StatsTable = new javax.swing.JTable();

        StatsTable.setModel(model_stats);
        StatsTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        StatsTable.setCellSelectionEnabled(false);
        StatsTable.setRowSelectionAllowed(true);
        StatsTableScrollPane.setViewportView(StatsTable);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(28, Short.MAX_VALUE)
                .addComponent(StatsTableScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 737, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(35, 35, 35))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(StatsTableScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(177, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable StatsTable;
    private javax.swing.JScrollPane StatsTableScrollPane;
    // End of variables declaration//GEN-END:variables

}
